#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;


class Solution {
public:
    void _sort(vector<int>& nums, int l, int r)
    {
        if (l >= r)return;
        int key = getkey(nums, l, r);
        int left = l - 1, right = r + 1;
        int i = l;
        while (i < right)
        {
            if (nums[i] < key)
            {
                swap(nums[++left], nums[i++]);
            }
            else if (nums[i] == key)
            {
                i++;
            }
            else {
                swap(nums[i], nums[--right]);
            }
        }
        //[l,left][left+1,right-1][right,r]
        _sort(nums, l, left);
        _sort(nums, right, r);
    }
    int getkey(vector<int>& nums, int l, int r)
    {
        int a = rand();
        return nums[a % (r - l + 1) + l];
    }
    vector<int> sortArray(vector<int>& nums) {
        srand(time(NULL));
        _sort(nums, 0, nums.size() - 1);
        return nums;
    }
};